const { toUrl, globalData } = getApp();
import { request } from "@/utils/request";
Page({
  toUrl,
  data: {
    headBc: "",
    globalData,
    currentIndex: 0,
    couponList: [],
    menu: 0,
    form: {
      typeid: 1,
      type: 0,
      page: 1,
    },
    count: 1,
    isExit: false,
    end: false,
  },
  swichTab(e) {
    const index = e.currentTarget.dataset.index;
    if (index == this.data.currentIndex) {
      return;
    }
    const form = this.data.form;
    form.page = 1;
    form.type = index;
    this.setData({
      menu: index,
      form: form,
      count: 1,
      isExit: false,
      couponList: [],
      currentIndex: index,
    });
    this.getList();
  },
  getList() {
    if (this.data.form.page > this.data.count) {
      this.setData({
        isExit: true,
      });
      return;
    }
    const that = this;
    const data = this.data.form;
    request("coupon/mycouponlist", { data }).then((res) => {
      const form = this.data.form;
      form.page = ++form.page;
      that.setData({
        couponList: that.data.couponList.concat(res.data),
        form: form,
        count: res.count,
      });
    });
  },

  onLoad(options) {
    this.getList();
  },

  onReachBottom() {
    if (isExit) {
      return;
    } else {
      this.getList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
